<template>
  <div class="message-container">
    <div class="item" v-for="(item, index) in list" :key="index">
      <div class="title" >{{ item.title }}({{ item.date }})</div>
      <div class="content"><el-link @click="Declaremessage()"><span v-html="item.message"></span></el-link></div>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      datetime:new Date().getFullYear()+"年"+(new Date().getMonth()+1)+"月"+new Date().getDate()+"日"
    }
  },
  props: {
    list: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  created() {
    this.Declaremessagelist();
  },
  methods: {
    Declaremessagelist() {
      var userlist=JSON.parse(localStorage.user)
      console.log(userlist)
      var dept_Id=userlist.dept_Id
      var role_Id=userlist.role_Id
      let url =
        "api/tb_project_declaremessage/GetDeclaremessageList"
      this.http.get(url, {}, true).then((res) => {
        //this.loading=true;
        console.log(res)
        //this.list=[];
        if(this.list.length==0)
        res.data.forEach(element => {
          if(element.receiverTypeId=="1"){
            this.list.push({
              title: element.informName,
              message: element.informContent,
              date: element.startDate,
              id:element.id
            });
          }
          if(element.receiverTypeId=="2"){
            var ids=element.receiverTypeItem.split(',')
            ids.forEach(element1 => {
              if(element1==dept_Id){
                this.list.push({
                  title: element.informName,
                  message: element.informContent,
                  date: element.startDate,
                  id:element.id
                });
              }
            });
           }
           if(element.receiverTypeId=="3"){
            var ids=element.receiverTypeItem.split(',')
            ids.forEach(element1 => {
              if(element1==role_Id){
                this.list.push({
                  title: element.informName,
                  message: element.informContent,
                  date: element.startDate,
                  id:element.id
                });
              }
            });
           }
        });
        console.log(res);
      });
    },
    Declaremessage(){
      this.$router.push('/tb_project_declaremessagelist');
    }
  },
};
</script>
<style scoped lang="less">
.message-container {
  .title {
    padding-bottom: 10px;
  }
  .item {
    border-bottom: 1px solid #eee;
    padding: 10px 20px;
  }
  .content {
    color: #7e7e7e;
    font-size: 13px;
  }
}
</style>
